//---------------------------------------------------------------------------

#include "vcl_stl.h"
#pragma hdrstop

#include "h_base.h"
#include "h_xml.h"
#include "h_global.h"
using namespace h_base;
using namespace h_xml;

#include "h_stage.h"
#include "t_dummyform.h"

#include "t_externjobform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TExternJobForm *ExternJobForm;
//---------------------------------------------------------------------------
__fastcall TExternJobForm::TExternJobForm(TComponent* Owner)
   : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TExternJobForm::ButtonOkClick(TObject *Sender)
{
   UTF8String ErrorString;

   Info.ExternGroup = EditExternGroup->Text.UpperCase().TrimRight();
   Info.ExternJob = EditExternJob->Text.UpperCase().TrimRight();
   Info.Description = GetStringFromMemo(MemoDescription);
   Info.Enlarge = ComboBoxEnlarge->Text.ToIntDef(0);

   if( !FStage->SetInfo(Info, ErrorString) )
   {
      ShowMessage(ErrorString);
      return;
   }

   OkFlag = true;
   Close();
}
//---------------------------------------------------------------------------

void __fastcall TExternJobForm::ButtonCancelClick(TObject *Sender)
{
   Close();
}
//---------------------------------------------------------------------------

bool __fastcall TExternJobForm::Edit(HStageExternJob *Stage)
{
   FStage = Stage;
   FStage->GetInfo(Info);
   UTF8String Cap;
   Cap.sprintf(UTF8String(DummyForm->PropertiesOf->Caption).c_str(),
      ( Info.ExternGroup + "." + Info.ExternJob ).c_str());
   Caption = Cap;
   EditExternGroup->Text = Info.ExternGroup;
   EditExternJob->Text = Info.ExternJob;
   SetStringToMemo(MemoDescription, Info.Description);

   if( ComboBoxEnlarge->Items->IndexOf(Info.Enlarge) == -1 )
      ComboBoxEnlarge->ItemIndex = 0;
   else
      ComboBoxEnlarge->ItemIndex =
         ComboBoxEnlarge->Items->IndexOf(Info.Enlarge);

   OkFlag = false;

   ShowModal();

   if( !OkFlag )
      return false;

   return true;
}

